package com.aspire.nm.component.miniServerDemo.server;

import com.aspire.nm.component.miniServer.Controll;
import com.aspire.nm.component.miniServer.annotation.Controller;
import com.aspire.nm.component.miniServer.annotation.Controller.MethodType;
import com.aspire.nm.component.miniServer.annotation.cls.Controllers;
import com.aspire.nm.component.miniServer.annotation.method.*;
import com.aspire.nm.component.miniServer.handle.Redirect;
import com.aspire.nm.component.miniServer.handle.ViewModel;
import com.aspire.nm.component.miniServerDemo.bean.Birthday;
import com.aspire.nm.component.miniServerDemo.bean.Person;
import com.aspire.nm.component.miniServerDemo.bean.Student;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

@Controllers(path="paytest/")
public class PaytestImpl implements Controll {

    
    
    /**
     * http://127.0.0.1:7072/paytest/hello?user=张三&age=15&iswomen=true&c=f
     * https://op-tester.ipaynow.cn/paytest/hello?user=%E5%BC%A0%E4%B8%89&age=15&iswomen=true&c=f
     */
    @Controller(desc="基本参数接收")
    public String hello(@ClientIp String clientIp,
            @ServerConfig(key="serverPort") String serverPort,
            @Header(key="User-Agent") String ua,
            @Req(key="user") String user,
            @Req(key="age") long age,
            @Req(key="c") char c,
            @Req(key="iswomen") boolean iswomen,
            @Session Map<String,Object> session,
            @JSessionId String jsessionId,
            @ServerConfig(key="sessionExpireSec") String sessionExpireSec){
        
        StringBuffer sb = new StringBuffer();
        sb.append("客户端IP =" + clientIp+"\r\n");
        sb.append("服务端PORT =" + serverPort+"\r\n");
        sb.append("header中ua =" + ua+"\r\n");
        sb.append("get参数user =" + user+"\r\n");
        sb.append("get参数age =" + age+"\r\n");
        sb.append("get参数c =" + c+"\r\n");
        sb.append("get参数iswomen =" + iswomen+"\r\n");
        sb.append("session超时 =" + sessionExpireSec+"\r\n");
        sb.append("jsessionId =" + jsessionId+"\r\n");
        if(session.get("count") == null){
            session.put("count", 1);
            sb.append("首次访问 " +"\r\n");
        }else{
            int count = ((Integer)session.get("count")).intValue();
            count ++;
            session.put("count", count);
            sb.append("访问次数 = "+count +"\r\n");
        }
        
        return sb.toString();
    }
    

}

